package cn.jeefast.rest.controller;


import cn.jeefast.common.entity.MbResearchData;
import cn.jeefast.common.utils.R;
import cn.jeefast.rest.service.MbResearchDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author theodo
 * @since 2019-12-30
 */
@RestController
@RequestMapping("/api")
public class MbResearchDataController {

    @Autowired
    private MbResearchDataService researchDataService;

    /**
     * 上报数据
     * @return
     */
    @RequestMapping("/researchData/update")
    public R update(MbResearchData researchData){
        researchData.setState(1);
        researchData.setUpdateDate(new Date());
        if(researchData.getDataImg1()!=null){
            researchData.setDataImg1Time(new Date());
        }
        if(researchData.getDataImg2()!=null){
            researchData.setDataImg2Time(new Date());
        }
        if(researchData.getDataImg3()!=null){
            researchData.setDataImg3Time(new Date());
        }
        if(researchData.getDataImg4()!=null){
            researchData.setDataImg4Time(new Date());
        }
        if(researchData.getDataImg5()!=null){
            researchData.setDataImg5Time(new Date());
        }
        if(researchData.getDataImg6()!=null){
            researchData.setDataImg6Time(new Date());
        }
        if(researchData.getDataImg7()!=null){
            researchData.setDataImg7Time(new Date());
        }
        if(researchData.getDataImg8()!=null){
            researchData.setDataImg8Time(new Date());
        }
        if(researchData.getDataImg9()!=null){
            researchData.setDataImg9Time(new Date());
        }
        researchDataService.updateById(researchData);
        return R.ok("").put("data",null);
    }

    /**
     * 审核未通过数据
     * @param docId
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/researchData/auditFailed")
    public R auditFailed(Long docId, Integer page, Integer limit) {
        page = (page-1)*limit;
        return researchDataService.auditFailed(docId,page,limit);
    }

    /**
     * 获取详情
     * @param dataId
     * @return
     */
    @RequestMapping("/researchData/detail")
    public R detail(Long dataId){
        MbResearchData mbResearchData = researchDataService.selectById(dataId);
        return R.ok().put("data",mbResearchData);
    }
}
